import db from "../models/index.js";
import {Op} from "sequelize";

let blockchain_price = db.blockchain_price;
let blockchainPriceDao = {};

// 添加币种信息
blockchainPriceDao.create = async (price, name, unicode, platform, selector, t) => {
  return blockchain_price.create({price, name, unicode, platform, selector}, {transaction: t});
};
// 修改币种价格
blockchainPriceDao.updatePrice = async (id, price, t) => {
  return blockchain_price.update({price}, {where: {id}, transaction: t});
};
// 查询币种根据unicode或者name
blockchainPriceDao.findByNameOrUnicode = async (name, unicode) => {
  return blockchain_price.findOne({where: {[Op.or]: [{name}, {unicode}]}});
};
// 查询币种根据unicode
blockchainPriceDao.findByName = async (name) => {
  return blockchain_price.findOne({where: {name}});
};
// 查询所有的币种
blockchainPriceDao.findAll = async () => {
  return blockchain_price.findAll({
    raw:true
  });
};

export default blockchainPriceDao;
